<?php
/**
 * Created by PhpStorm.
 * User: chengyu
 * Date: 2021/6/7 0007
 * Time: 19:45
 */

namespace app\api\controller\v1;

use app\BaseController;
use app\common\model\Banner;
use app\common\model\Cate;
use app\common\model\Cooperation;
use app\common\model\Product;

class Coop extends BaseController
{
    //获取供应合作
    //程宇
    public function index()
    {
        return sucessMsg('200', '获取成功', [
            'banner' => $this->banner(),//获取banner
            'tag' => $this->tag(),//获取banner图上标签
            'coop'=>$this->coop(),//获取供应合作信息
            'product' => $this->product(),////获取供应合作优势
        ]);
    }

    //获取banner
    public function banner()
    {
        $model = New Banner();
        $banner = $model->where(['status' => 1, 'type' => 9])
            ->field('id,title,image')
            ->order('sort', 'asc')
            ->select();
        foreach ($banner as $v) {
            $v['image'] = env('app.yuming') . $v['image'];
        }
        return $banner;
    }

    /**
     * 获取首页banner标签
     */
    public function tag()
    {
        $model = New Cate();
        $type = [1, 2, 3];
        $tag = $model->where('status', 1)
            ->where('type', 'in', $type)
            ->field('id,name,image')
            ->select();
        foreach ($tag as $v) {
            $v['image'] = env('app.yuming') . $v['image'];
        }
        return $tag;
    }

    public function coop()
    {
        $model = New Cooperation();
        $coop = $model->where('status', 1)
            ->field('id,introduce,requirement,remarks')
            ->find();
        return $coop;
    }

    //获取
    public function product()
    {
        $model = New Product();
        $coop = $model->where('status', 1)
            ->where('type',2)
            ->field('id,content,title,image')
            ->select();
        foreach ($coop as &$v) {
            $v['image'] = env('app.yuming') . $v['image'];
        }
        return $coop;
    }

}